package com.btpn.custody.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.NamedQueries;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.btpn.infra.entity.AEntityLong;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true, dynamicUpdate=true)
@Table(name = "M_REGION")
@NamedQueries({
	@NamedQuery(name  = "Region.getByCode",
				query = "FROM Region r WHERE r.code = :regionCode"),
	@NamedQuery(name  = "Region.getByName",
				query = "FROM Region r WHERE r.name = :regionName")
})
public class Region extends AEntityLong {
	/*=============================================== C O N S T A N T =========================================*/
	private static final long serialVersionUID = -7638850514933720542L;
	
	public static final String NQ__FIND__BY__CODE = "Region.getByCode";
	
	public static final String NQ__FIND__BY__NAME = "Region.getByName";
		
	/*=============================================== M E M B E R =============================================*/
	@Column(name = "REGION_CODE", unique=true)
	private String code;
	
	@Column(name = "REGION_NAME")
	private String name;

	@OneToMany(cascade = {CascadeType.REFRESH}, mappedBy = "region")
	private List<Area> areas = new ArrayList<Area>();
	
	/*=============================================== G E T T E R   &   S E T T E R ===========================*/
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<Area> getAreas() {
		return areas;
	}

	public void setAreas(List<Area> areas) {
		this.areas = areas;
	}
}
